package com.cxy.mapper;

import com.cxy.dto.AllMessageDTO;
import com.cxy.dto.PageDTO;
import com.cxy.dto.UserDTO;
import com.cxy.dto.UserLoginDTO;
import com.cxy.entity.User;
import com.cxy.result.PageResult;
import com.cxy.vo.UserVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 根据密码和用户名查询用户信息得到jwt令牌
     * @param userLoginDTO
     * @return
     */
    @Select("select *from user where username=#{username} and password=#{password} ")
    User login(UserLoginDTO userLoginDTO);

    /**
     * 分页条件查询
     * @param pageDTO
     * @return
     */
    Page<User> pageAndSelect(PageDTO pageDTO);

    /**
     * 新增用户
     * @param userDTO
     */
    @Insert("insert into user(name, gender, phone, email, user_type) VALUES(#{name},#{gender},#{phone},#{email},#{userType})")
    void saveUser(UserDTO userDTO);

    /**
     * 根据id查询党员信息
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id}")
    User getById(Long id);

    /**
     * 修改党员基本信息
     * @param allMessageDTO
     */
    void update(AllMessageDTO allMessageDTO);

    /**
     * 删除用户
     * @param ids
     */
    void delete(List<Long> ids);

    /**
     * 查询所有
     * @return
     */
    @Select("select *from user")
    List<UserVO> select();

    /**
     * 根据邮箱查有没有该用户
     * @param email
     * @return
     */
    @Select("select *from user where email=#{email}")
    User selectEmail(String email);
}
